package net.caixiaomi.info.ui.football.detail;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.caixiaomi.info.R;
import net.caixiaomi.info.adapter.MatchDetailLiveAdapter;
import net.caixiaomi.info.adapter.MatchDetailOddsAdapter;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.BaseFragment;
import net.caixiaomi.info.base.progressbar.CircularProgressBar;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.interfaces.ComonFragmentImpl;
import net.caixiaomi.info.model.MatchIntroduceModel;
import net.caixiaomi.info.model.MatchLiveDataEntity;
import net.caixiaomi.info.model.MatchLiveEventEntity;
import net.caixiaomi.info.model.MatchLiveModel;
import net.caixiaomi.info.model.MathLiveDataNullEntity;
import net.caixiaomi.info.util.Constants;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by suntian on 2018/7/24.
 */

public class MatchLiveFragment extends BaseFragment implements ComonFragmentImpl {

    @BindView(android.R.id.list)
    RecyclerView mListView;
    @BindView(net.caixiaomi.info.R.id.progress)
    CircularProgressBar mProgress;

    private MatchDetailLiveAdapter mAdapter;
    private MatchLiveModel mData;

    private MatchIntroduceModel mMatchIntroduceModel;  //全局数据

    @Override
    protected int fragmentLayout() {
        return R.layout.frag_list;
    }

    @Override
    protected void onFragmentCreated(View view, @Nullable Bundle savedInstanceState) {
        mProgress.setVisibility(View.GONE);
        mListView.setLayoutManager(new LinearLayoutManager(getActivity()));

        mAdapter = new MatchDetailLiveAdapter(null);
        mListView.setAdapter(mAdapter);

    }

    public void setData(MatchLiveModel data) {
        mData = data;
        updateDisplayData();
    }

    public void setMatchDetailData(MatchIntroduceModel model){
        mMatchIntroduceModel=model;
        mAdapter.setMatchDetailData(model);
    }

    private void updateDisplayData() {
        try {
            List<MultiItemEntity> data = new ArrayList<>();
            data.addAll(mData.getEventList());

            if(data.size()>0) {

                MatchLiveEventEntity entity0 = new MatchLiveEventEntity();
                entity0.setType(Constants.ITEM_MATCH_LIVE0);
                data.add(0, entity0);

                MatchLiveEventEntity entity2 = new MatchLiveEventEntity();
                entity2.setType(Constants.ITEM_MATCH_LIVE2);
                data.add(data.size(), entity2);

            }else{
                MatchLiveEventEntity entity0 = new MatchLiveEventEntity();
                entity0.setType(Constants.ITEM_MATCH_LIVE0_NODATA);
                data.add(0, entity0);

                MatchLiveEventEntity entity2 = new MatchLiveEventEntity();
                entity2.setType(Constants.ITEM_MATCH_LIVE2);
                data.add(data.size(), entity2);
            }
            if(mData.getMatchLiveStatisticsDTO()==null||mData.getMatchLiveStatisticsDTO().size()==0){
                MatchLiveEventEntity entity3 = new MatchLiveEventEntity();
                entity3.setType(Constants.ITEM_MATCH_LIVE3);
                List<MatchLiveDataEntity> list=new ArrayList<>();
                String[]dateName={"控球率","射正","射偏","被封堵","角球","任意球","越位","黄牌","犯规","有威胁攻势"};
                for(int i=0;i<dateName.length;i++){
                    MatchLiveDataEntity entity=new MatchLiveDataEntity();
                    entity.setDataName(dateName[i]);
                    entity.setTeamAData("");
                    entity.setTeamHData("");
                    list.add(entity);
                }
                entity3.setMatchTotals(list);
                data.add(data.size(), entity3);
            }else{
                MatchLiveEventEntity entity3 = new MatchLiveEventEntity();
                entity3.setType(Constants.ITEM_MATCH_LIVE3);
                entity3.setMatchTotals(mData.getMatchLiveStatisticsDTO());
                data.add(data.size(), entity3);
            }

            mAdapter.setNewData(data);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void setType(int type) {

    }

    @Override
    public void setFilter(String filter) {

    }
}
